# -*- coding: utf-8 -*-
# @Time    : 2021/10/21 3:26 下午
# @Author  : CHENlj
# @File    : Ftp_server.py
import os
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer

# 项目目录
project_path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))
# data文件夹路径
data_path = os.path.join(project_path, 'Data')

# 实例化DummyAuthorizer来创建ftp用户
authorizer = DummyAuthorizer()
# 参数：用户名，密码，目录，权限
authorizer.add_user('admin', '123456', data_path, perm='elradfmwMT')
# 匿名登录
# authorizer.add_anonymous('/home/nobody')
handler = FTPHandler
handler.authorizer = authorizer
# 参数：IP，端口，handler
server = FTPServer(('0.0.0.0', 21), handler)           #设置为0.0.0.0为本机的IP地址
server.serve_forever()

if __name__ == '__main__':
    print('data', data_path)